package tresp.utils;

import java.util.AbstractQueue;
import java.util.concurrent.LinkedBlockingQueue;


/**
 * 
 * 
 * @author <font color="blue">Maxim Kirilov</font>
 *
 */
public class PatternAnalyzer implements Runnable{

    private AbstractQueue<DataLink> links;

    private boolean isActive = true;


    public PatternAnalyzer(){
	links = new LinkedBlockingQueue<DataLink>();
    }

    public void add(SymbolicPatternNode node, String pattern, int idx){
	links.add( new DataLink(node, pattern, idx) );
    }

    public void remove() {
	links.poll();
    }


    public void stopAnalyzer() {
	isActive = false;
    }


    @Override
    public void run() {
	while ( isActive ) {
	    
	    try {
		DataLink dl = ((LinkedBlockingQueue<DataLink>) links).take();
		SymbolicPatternNode node = dl.getSp();
		String pattern = dl.getPattern();
		Integer idx = dl.getId();
		node.addSequence(pattern, idx);
	    } catch (InterruptedException e) {

	    }
	    


	}

    }
    
    
    private class DataLink{
	
	private SymbolicPatternNode sp;
	private String pattern;
	private Integer id;
	
	public DataLink(SymbolicPatternNode sp, String pattern, Integer id){
	    setSp(sp);
	    setPattern(pattern);
	    setId(id);
	}
	
	
	public SymbolicPatternNode getSp() {
	    return sp;
	}
	public void setSp(SymbolicPatternNode sp) {
	    this.sp = sp;
	}
	public String getPattern() {
	    return pattern;
	}
	public void setPattern(String pattern) {
	    this.pattern = pattern;
	}
	public Integer getId() {
	    return id;
	}
	public void setId(Integer id) {
	    this.id = id;
	}
	
	
	
	
    }

}


